<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>积分规则</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://at.alicdn.com/t/font_1805932_ysrcp4y0uy9.css">
    <link rel="stylesheet" href="css/uploadImg.css">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>规则名称:</label>
                                <input type="text" class="form-control" name="ruleName">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加积分规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑积分规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-danger btn_query btn-round" type="button" id="deleteBtn">删除积分规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="bindBtn">绑定积分商品</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" id="unBindBtn">解绑积分商品</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-purple btn_query btn-round" type="button" id="initBrowserBtn">初始化浏览赚积分比例</button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="card-body">
                    <table id="grid_data" class="table text-nowrap"></table>
                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <span>添加/编辑</span>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <div id="error_tips" style="color: #c9302c"></div>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm" method="post" enctype="multipart/form-data">
                        <div class="row">

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="basic-account">规则名称</span>
                                    <input type="hidden" name="id">
                                    <input type="text" name="ruleName" class="form-control">
                                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">积分类型</span>
                                    <select name="integralType" class="form-control">
                                        <option value="1">积分抵用比例(1积分抵多少金额)</option>
                                        <option value="2">下单赠送积分比例（实际支付1元赠送多少积分）</option>
                                        <option value="3">浏览商品赚积分比例</option>
                                    </select>
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">转换比例</span>
                                    <input type="text" name="convertRatio" class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-.]+/,'').replace(/^([1-9]\d*(\.[\d]{0,2})?|0(\.[\d]{0,2})?)[\d.]*/g, '$1');">
                                    <span class="input-group-addon">转换比例</span>
                                    <input type="text" name="convertEnd" class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-.]+/,'').replace(/^([1-9]\d*(\.[\d]{0,2})?|0(\.[\d]{0,2})?)[\d.]*/g, '$1');">
                                </div>
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary addSaveBtn" id="saveBtn">保存</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>

    <!-- 秒杀、拼团、砍价绑定解绑 -->
    <div class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">解绑或绑定操作</h4>
                </div>
                <div class="modal-body">
                    <div id="myTabContent" class="tab-content">
                        <form class="form-inline" method="post" id="searchGoodsForm">
                            <div class="form-group">
                                <label>商品名称:</label>
                                <input type="text" class="form-control" name="productName">
                                <input type="hidden" name="bindStatus" value="0" id="bindStatus">
                                <label>所属板块 :</label>
                                <select name="moudleId" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">默认</option>
                                    <option value="1">秒杀</option>
                                    <option value="2">拼团</option>
                                    <option value="3">砍价</option>
                                    <option value="4">新人专享</option>
                                    <option value="5">积分兑换</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>商品分类:</label>
                                <input type="text" class="form-control" name="typeName">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchGoodsBtn">查询</button>
                            </div>
                        </form>
                    </div>
                    <div class="tab-content p-10">
                        <table id="seckill_data" class="table text-nowrap"></table>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="operationBtn">确定</button>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.curd.js"></script>
    <script type="text/javascript">

        var goodsColumns = [
            {checkbox: true},
            {field: 'id',title: '商品ID'},
            {field: 'productName',title: '商品名称', width: 60},
            {field: 'moudleId',title: '所属板块', formatter: function (value) { return value == 0 ? "默认" : value == 1 ? "秒杀" : value == 2 ? "拼团" : value == 3 ? "砍价" : value == 4 ? "新人专享" : "积分兑换"}},
            {field: 'businessId',title: '商家ID'},
            {field: 'businessName',title: '商家名称'},
            {field: 'typeId',title: '商品分类ID'},
            {field: 'typeName',title: '商品分类名称'},
            {field: 'barCode',title: '商品条形码'},
            {field: 'warningValue',title: '商品预警值'},
            {field: 'brandId',title: '品牌ID',visible: false},
            {field: 'brandName',title: '品牌名称'},
            {field: 'skuName',title: 'SKU名称'},
            {field: 'productUnit',title: '商品单位'},
            {field: 'productWeight',title: '商品重量'},
            {field: 'productWeightUnit',title: '商品重量单位'},
            {field: 'productPlace',title: '商品生产地'},
            {field: 'productSort',title: '商品排序'},
            {field: 'buyLimit',title: '限购数量'},
            {field: 'produceTime',title: '生产日期'},
            {field: 'lifeTime',title: '保质期'},
            {field: 'lifeTimeUnit',title: '保质期单位'},
            {field: 'storeCondition',title: '存储条件'},
            {field: 'productStock',title: '商品库存'},
            {field: 'soldStock',title: '已售数量'},
            {field: 'saleAmount',title: '虚拟销量'},
            {field: 'supplyPrice',title: '供货价'},
            {field: 'marketPrice',title: '原价'},
            {field: 'productPrice',title: '零售价'},
            {field: 'saleAreaName',title: '销售区域'},
            {field: 'apply_time',title: '商品创建时间', formatter: function (value) {return zero2one.dateFormat(value, 'Y-m-d H:i:s')}},
            {field: 'approve_time',title: '审核时间', formatter: function (value) {return zero2one.dateFormat(value, 'Y-m-d H:i:s')}},
            {field: 'approve_name',title: '审核人'},
            {field: 'approve_result',title: '审核结果'}
        ];

        //进入主界面加载数据
        zero2one.datagrids("seckill_data", "/remote/communityGoods/list",function (params) {
            return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchGoodsForm"));
        }, goodsColumns, function (data) {});
        //点击查询按钮重新加载页面数据
        $("#searchGoodsBtn").click(function () {
            $('#seckill_data').bootstrapTable('refresh');
        });
        //绑定
        $("#bindBtn").click(function () {
            var datas = $("#grid_data").bootstrapTable('getSelections');
            if(datas.length == 1){
                $("#bindStatus").val(1);
                $("#myModal").modal("show");
            }else {
                $.messager.alert("温馨提示", "请选择一条规则绑定");
            }
        });
        //解绑
        $("#unBindBtn").click(function () {
            $("#bindStatus").val(0);
            $("#myModal").modal("show");
        });
        //绑定、解绑操作
        $("#operationBtn").click(function () {
            var dataes = $("#seckill_data").bootstrapTable('getSelections');
            if(dataes.length >= 1){
                if($("#bindStatus").val() == 1){//绑定
                    $.messager.confirm("温馨提示", "您确定要绑定该商品吗?", function () {
                        var datas = $("#grid_data").bootstrapTable('getSelections');
                        zero2one.request("/remote/communityGoods/bind",{productIds : zero2one.dynamicArray2str(dataes, "id"), ruleId: zero2one.dynamicArray2str(datas, "id"), moudleId : 5},function (data) {
                            window.location.reload();
                        });
                    })
                }else {//解绑
                    $.messager.confirm("温馨提示", "您确定要解绑该商品吗?", function () {
                        zero2one.request("/remote/communityGoods/unBind",{productIds : zero2one.dynamicArray2str(dataes, "id")},function (data) {
                            window.location.reload();
                        });
                    })
                }
            }else {
                $.messager.alert("温馨提示", "请选择一条或多条记录进行绑定或解绑");
            }
        });

        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'id',title: '编号'},
            {field: 'ruleName',title: '规则名称'},
            {field: 'integralType',title: '积分类型',formatter: function (value, row, index) {return value == 1 ? "积分抵用比例": value == 2 ? "下单赠送积分比例": "浏览赚积分比例"}},
            {field: 'convertRatio',title: '转换比例'},
            {field: 'convertEnd',title: '转换比例'},
        ];

        //加载列表信息
        zero2one.table("/remote/integral/list", columns);

        //根据条件查询列表信息
        zero2one.query();

        //点击删除按钮
        zero2one.delete("/remote/integral/deleteByIds");

        //点击添加按钮弹出模态框
        zero2one.addModal();

        //点击编辑按钮弹出模态框
        zero2one.editModal();

        //点击保存按钮提交请求且提交前先执行表单验证
        $('#addOrEditForm').bootstrapValidator({
            fields: {
                ruleName: {validators: {notEmpty: {message: '规则名称不能为空'}}},
                convertRatio: {validators: {notEmpty: {message: '转换比例不能为空'}}}
            }
        });
        zero2one.save("/remote/integral/addOrEdit");

        //初始化浏览赚积分比例
        $("#initBrowserBtn").click(function () {
            var datas = $("#grid_data").bootstrapTable('getSelections');
            if(datas.length == 1){
                zero2one.request("/remote/integral/initBrowser", datas[0], function (data) {
                    window.location.reload();
                });
            }else {
                $.messager.alert("温馨提示", "请选择一条浏览赚积分规则初始化");
            }
        })

    </script>
</div>
</body>
</html>
